|
1
|
|
|
/* |
|
2
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* @author Julius Härtl <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
app.factory('StackService', function(ApiService, $http, $q){ |
|
24
|
|
|
var StackService = function($http, ep, $q) { |
|
25
|
|
|
ApiService.call(this, $http, ep, $q); |
|
26
|
|
|
}; |
|
27
|
|
|
StackService.prototype = angular.copy(ApiService.prototype); |
|
28
|
|
|
StackService.prototype.fetchAll = function(boardId) { |
|
29
|
|
|
var deferred = $q.defer(); |
|
30
|
|
|
var self=this; |
|
31
|
|
|
$http.get(this.baseUrl +'/'+boardId).then(function (response) { |
|
32
|
|
|
self.clear(); |
|
33
|
|
|
self.addAll(response.data); |
|
34
|
|
|
deferred.resolve(self.data); |
|
35
|
|
|
}, function (error) { |
|
|
|
|
|
|
36
|
|
|
deferred.reject('Error while loading stacks'); |
|
37
|
|
|
}); |
|
38
|
|
|
return deferred.promise; |
|
39
|
|
|
}; |
|
40
|
|
|
|
|
41
|
|
|
StackService.prototype.fetchArchived = function(boardId) { |
|
42
|
|
|
var deferred = $q.defer(); |
|
43
|
|
|
var self=this; |
|
44
|
|
|
$http.get(this.baseUrl +'/'+boardId+'/archived').then(function (response) { |
|
45
|
|
|
self.clear(); |
|
46
|
|
|
self.addAll(response.data); |
|
47
|
|
|
deferred.resolve(self.data); |
|
48
|
|
|
}, function (error) { |
|
|
|
|
|
|
49
|
|
|
deferred.reject('Error while loading stacks'); |
|
50
|
|
|
}); |
|
51
|
|
|
return deferred.promise; |
|
52
|
|
|
}; |
|
53
|
|
|
|
|
54
|
|
|
StackService.prototype.addCard = function(entity) { |
|
55
|
|
|
if(!this.data[entity.stackId].cards) { |
|
56
|
|
|
this.data[entity.stackId].cards = []; |
|
57
|
|
|
} |
|
58
|
|
|
this.data[entity.stackId].cards.push(entity); |
|
59
|
|
|
}; |
|
60
|
|
|
|
|
61
|
|
|
StackService.prototype.reorder = function(entity, order) { |
|
62
|
|
|
// assign new order |
|
63
|
|
|
for(var i=0, j=0;i<this.data[entity.stackId].cards.length;i++) { |
|
64
|
|
|
if(this.data[entity.stackId].cards[i].id === entity.id) { |
|
65
|
|
|
this.data[entity.stackId].cards[i].order = order; |
|
66
|
|
|
} |
|
67
|
|
|
if(j === order) { |
|
68
|
|
|
j++; |
|
69
|
|
|
} |
|
70
|
|
|
if(this.data[entity.stackId].cards[i].id !== entity.id) { |
|
71
|
|
|
this.data[entity.stackId].cards[i].order = j++; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
// sort array by order |
|
75
|
|
|
this.data[entity.stackId].cards.sort(function(a,b) { |
|
76
|
|
|
if (a.order < b.order) |
|
77
|
|
|
return -1; |
|
|
|
|
|
|
78
|
|
|
if (a.order > b.order) |
|
79
|
|
|
return 1; |
|
|
|
|
|
|
80
|
|
|
return 0; |
|
81
|
|
|
}); |
|
82
|
|
|
}; |
|
83
|
|
|
|
|
84
|
|
|
StackService.prototype.updateCard = function(entity) { |
|
85
|
|
|
var self = this; |
|
|
|
|
|
|
86
|
|
|
var cards = this.data[entity.stackId].cards; |
|
87
|
|
|
for(var i=0;i<cards.length;i++) { |
|
88
|
|
|
if(cards[i].id == entity.id) { |
|
89
|
|
|
cards[i] = entity; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
}; |
|
93
|
|
|
StackService.prototype.removeCard = function(entity) { |
|
94
|
|
|
var self = this; |
|
|
|
|
|
|
95
|
|
|
var cards = this.data[entity.stackId].cards; |
|
96
|
|
|
for(var i=0;i<cards.length;i++) { |
|
97
|
|
|
if(cards[i].id == entity.id) { |
|
98
|
|
|
cards.splice(i, 1); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
}; |
|
102
|
|
|
|
|
103
|
|
|
service = new StackService($http, 'stacks', $q); |
|
|
|
|
|
|
104
|
|
|
return service; |
|
105
|
|
|
}); |
|
106
|
|
|
|
|
107
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.